package com.aso114.project.dialog;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.aso114.project.R;
import com.aso114.project.base.BaseDialog;
import com.aso114.project.util.ScreenTools;

public class ExamTimeDialog extends BaseDialog implements View.OnClickListener {
    private OnDialogClick onDialogClick;
    private Context mContext;
    private String num = "";
    private String day = "";

    public ExamTimeDialog(Context context,String num,String day,OnDialogClick onDialogClick) {
        super(context);
        this.mContext = context;
        this.num = num;
        this.day = day;
        this.onDialogClick = onDialogClick;
        init();
    }

    private void init() {
        View contentView = LayoutInflater.from(mContext).inflate(R.layout.exam_time_dialog, null);
        setContentView(contentView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        Window window = getWindow();
        // 设置显示动画
        WindowManager.LayoutParams wl = window.getAttributes();
        wl.x = 0;
        wl.y = ScreenTools.getScreenHeight(mContext);
        // 以下这两句是为了保证按钮可以水平满屏
        wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
        wl.height = ViewGroup.LayoutParams.MATCH_PARENT;
        // 设置显示位置
        this.onWindowAttributesChanged(wl);
        this.setCancelable(false);
        this.setCanceledOnTouchOutside(false);
        contentView.findViewById(R.id.exam_time_close).setOnClickListener(this);
        contentView.findViewById(R.id.exam_time_buy).setOnClickListener(this);
        TextView tvNum = contentView.findViewById(R.id.exam_time_num);
        TextView tvDay = contentView.findViewById(R.id.exam_time_day);
        tvNum.setText(num);
        tvDay.setText("距离"+day+"考试");
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.exam_time_close:
                dismiss();
                break;

            case R.id.exam_time_buy:
                if (onDialogClick != null)
                    onDialogClick.goBuy();
                dismiss();
                break;
        }
    }

    public interface OnDialogClick {
        void goBuy();
    }
}
